<template>
    <div class="layout-header-container">
        <div class="layout-header-left">
            <img class="layout-header-left-img" src="../assets/logo.svg" alt="">
            <h4 class="layout-header-left-title ml-3">商城后台管理系统</h4>
        </div>
        <div class="layout-header-right">
            <button type="button" class="btn btn-light"
            @click="open">
                退出
            </button>
        </div>
    </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
const router = useRouter()
import { ElMessage, ElMessageBox } from 'element-plus'
const open = () => {
    ElMessageBox.confirm(
        '你确定要退出登录吗？', 
        '确认退出', 
        {
            confirmButtonText: '退出登录',
            cancelButtonText: '取消退出',
            type: 'warning',
        }
    ).then(() => {
        // 确认后
        toLogout()
    }).catch(() => {
        // 提示
        ElMessage({
            type: 'info',
            message: '用户取消退出',
        })
    })
}
const toLogout = () => {
    // 移出token
    sessionStorage.removeItem('token')
    router.push('/login')
}
</script>

<style scoped>
.layout-header-container {
    height: 60px;
    border-bottom: 1px solid #eaeaea;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.5rem;
    background-color: #5f9ea0;

    .layout-header-left {
        display: flex;
        align-items: center;
        color: #fff;
    }
}

.layout-header-left-img {
    height: 50px;
}

.layout-header-right {
    .btn {
        background-color: #5f9ea0;
        color: #fff;
    }

    .btn:hover {
        color: #999;
        opacity: 0.5;
        background-color: #fff;
    }
}
</style>